﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Customers.aspx.cs" Inherits="Companies_Customers" Title="Клиенти" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />    
    <p>
        &nbsp;</p>
    <p>
        СПИСЪК НА КЛИЕНТИТЕ 
        <asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" 
            DataSourceID="sdsCustomers" Width="982px" DataKeyNames="CustomerID" 
            onselectedindexchanged="gvCustomers_SelectedIndexChanged" 
            BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
            CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <Columns>
                <asp:CommandField SelectText="Избери" ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идент. № по ЗДДС/VATNO" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ" 
                    SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="NameBG" HeaderText="Държава" 
                    SortExpression="NameBG" />
                <asp:TemplateField HeaderText="Продукти">
                    <ItemTemplate>
                      <a href='CustProducts.aspx?CustomerID=<%# Eval("CustomerID") %>'>Продукти</a> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        
        </p>
    <p>
        <asp:DetailsView ID="dvCustomers" runat="server" AllowPaging="True" 
            AutoGenerateRows="False" DataKeyNames="CustomerID" 
            DataSourceID="sdsCustomerDetails" Height="50px" Width="385px" 
            onitemdeleted="dvCustomers_ItemDeleted" 
            oniteminserted="dvCustomers_ItemInserted" 
            onitemupdated="dvCustomers_ItemUpdated" 
            onpageindexchanging="dvCustomers_PageIndexChanging" BackColor="White" 
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            ForeColor="Black" GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <Fields>
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="AddressInvoice" HeaderText="Адрес за фактури" 
                    SortExpression="AddressInvoice" />
                <asp:BoundField DataField="AddressCorrespondence" 
                    HeaderText="Адрес за кореспонденция" SortExpression="AddressCorrespondence" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идентификационен № по ЗДДС/VAT" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ:" SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="Website" HeaderText="Уебсайт" SortExpression="Website" />
                <asp:BoundField DataField="Bank" HeaderText="Банка" SortExpression="Bank" />
                <asp:BoundField DataField="BankAddress" HeaderText="Адрес на банката" 
                    SortExpression="BankAddress" />
                <asp:BoundField DataField="AccountNo" HeaderText="Сметка №" SortExpression="AccountNo" />
                <asp:BoundField DataField="IBAN" HeaderText="IBAN" SortExpression="IBAN" />
                <asp:BoundField DataField="BIC" HeaderText="BIC" SortExpression="BIC" />
                <asp:BoundField DataField="BankGiro" HeaderText="BankGiro" SortExpression="BankGiro" />
                <asp:BoundField DataField="PostGiro" HeaderText="PostGiro" SortExpression="PostGiro" />
                <asp:TemplateField HeaderText="Държава" SortExpression="NameBG">
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlCountries" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="ddlCountriesIns" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("NameBG") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowInsertButton="True" CancelText="Прекъсни" DeleteText="Изтриване" 
                    EditText="Редактиране" InsertText="Вмъкване" NewText="Нов" SelectText="Избери" 
                    UpdateText="Обнови" />
            </Fields>
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <HeaderTemplate>
                Детайли
                <br />
            </HeaderTemplate>
            <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:DetailsView>
        <asp:SqlDataSource ID="sdsCustomers" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            
            SelectCommand="SELECT Customers.CustomerID, Customers.IDNUM, Customers.Name, Customers.VATNO, Customers.MRP, Customers.Phone, Customers.Fax, Countries.NameBG FROM Customers INNER JOIN Countries ON Customers.CountryID = Countries.CountryID ">
        </asp:SqlDataSource>
    </p>
    <p>
        <asp:Button ID="btnNewCustomer" runat="server" Text="Създай нов Клиент" 
            onclick="btnNewCustomer_Click" />
    </p>
    <p>
        <asp:SqlDataSource ID="sdsCountries" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            
            SelectCommand="SELECT [CountryID], [NameBG] FROM [Countries] ORDER BY NameBG">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="sdsCustomerDetails" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" 
            InsertCommand="INSERT INTO [Customers] ([Name], [AddressCorrespondence], [AddressInvoice], [IDNUM], [VATNO], [MRP], [Phone], [Fax], [Website], [Bank], [BankAddress], [AccountNo], [BIC], [IBAN], [BankGiro], [PostGiro], [CountryID]) VALUES (@Name, @AddressCorrespondence, @AddressInvoice, @IDNUM, @VATNO, @MRP, @Phone, @Fax, @Website, @Bank, @BankAddress, @AccountNo, @BIC, @IBAN, @BankGiro, @PostGiro, @CountryID)" 
            SelectCommand="SELECT Customers.CustomerID, Customers.Name, Customers.AddressCorrespondence, Customers.AddressInvoice, Customers.IDNUM, Customers.VATNO, Customers.MRP, Customers.Phone, Customers.Fax, Customers.Website, Customers.Bank, Customers.BankAddress, Customers.AccountNo, Customers.BIC, Customers.IBAN, Customers.BankGiro, Customers.PostGiro, Countries.NameBG FROM Customers INNER JOIN Countries ON Customers.CountryID = Countries.CountryID WHERE (Customers.CustomerID = @CustomerID)" 
            UpdateCommand="UPDATE [Customers] SET [Name] = @Name, [AddressCorrespondence] = @AddressCorrespondence, [AddressInvoice] = @AddressInvoice, [IDNUM] = @IDNUM, [VATNO] = @VATNO, [MRP] = @MRP, [Phone] = @Phone, [Fax] = @Fax, [Website] = @Website, [Bank] = @Bank, [BankAddress] = @BankAddress, [AccountNo] = @AccountNo, [BIC] = @BIC, [IBAN] = @IBAN, [BankGiro] = @BankGiro, [PostGiro] = @PostGiro, [CountryID] = @CountryID WHERE [CustomerID] = @CustomerID">
            <SelectParameters>
                <asp:ControlParameter ControlID="gvCustomers" PropertyName="SelectedValue" Name="CustomerID" Type="Int32" />
                
            </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="CustomerID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvCustomers$ddlCountries" PropertyName="SelectedValue" />
                <asp:Parameter Name="CustomerID" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvCustomers$ddlCountriesIns" PropertyName="SelectedValue" />
            </InsertParameters>
        </asp:SqlDataSource>
    </p>
    <p>
        &nbsp;</p>
</asp:Content>

